window.album = {
    serverUrl: "http://127.0.0.1",

    saveToken: function (token) {
        localStorage.setItem("token", token)
    },

    logout: function () {
        localStorage.removeItem("token")
        localStorage.removeItem("user")
    },

    getToken: function () {
        return localStorage.getItem("token")
    },

    getUserInfor: function () {
        return localStorage.getItem("user")
    },

    setUserInfor: function (data) {
        return localStorage.setItem("user", data)
    },

    checkLogin: function ($) {
        let token = this.getToken()
        if (!token) {
            layer.msg("客官,请先登录", {icon: 1})
            setTimeout(function () {
                window.location.href = "login.html"
            }, 1500)
        }
    },

    seeImage: function (url) {
        let img = new Image();
        img.src = url;
        let html = '<div class="wrap">';
        html += '<img style="width: 100%;" src="' + app.serverUrl + '/' + url + '"/>';
        html += '</div>';
        //弹出层
        layui.layer.open({
            type: 1,
            shade: 0.8,
            offset: 'auto',
            area: [550 + 'px', 650 + 'px'], // area: [width + 'px',height+'px'] //原图显示
            shadeClose: false,
            scrollbar: false,
            title: "图片预览", //不显示标题
            content: html, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            cancel: function () {
                //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });
            }
        });

    },
    getQueryString: function () {
        let qs = location.search.substr(1), // 获取url中"?"符后的字串
            args = {}, // 保存参数数据的对象
            items = qs.length ? qs.split("&") : [], // 取得每一个参数项,
            item = null,
            len = items.length;

        for (var i = 0; i < len; i++) {
            item = items[i].split("=");
            var name = decodeURIComponent(item[0]),
                value = decodeURIComponent(item[1]);
            if (name) {
                args[name] = value;
            }
        }
        return args;
    }

}
